#!/user/bin/env python3
# -*- coding: utf-8 -*-
"""
--------------------------------------
    Author:     JiChao_Song
    Date  :     2020/11/13 12:17
    Desc  :
--------------------------------------
"""
import logging

from flask_migrate import MigrateCommand

from application import manager, app
import routes
import middle

import pymysql

from servers.models.userModel import User

pymysql.install_as_MySQLdb()


@manager.option('-u', '--username', dest = 'username')
@manager.option('-p', '--password', dest = 'password')
def createSuperUser(username, password):
    """
    新增超级用户
    """

    try:
        user = User(username = username, password = password, admin = 100, is_superuser = True)

        user.save()

        print('添加成功')
    except Exception as e:
        print('添加失败')


if __name__ == '__main__':
    handler = logging.FileHandler('flask.log', encoding = 'utf-8')
    formatter = logging.Formatter(
        "%(asctime)s - %(levelname)s - %(filename)s - %(funcName)s - %(lineno)s - %(message)s'")
    handler.setFormatter(formatter)
    app.logger.addHandler(handler)
    # app.run(
    #     host = app.config['SERVER_HOST'],
    #     port = app.config['SERVER_PORT'],
    #     debug = app.config['DEBUG'],
    # )
    manager.run()